package com.atguigu.atcrowdfunding.manager.service.impl;

import com.atguigu.atcrowdfunding.bean.Advertisement;
import com.atguigu.atcrowdfunding.bean.Role;
import com.atguigu.atcrowdfunding.manager.dao.AdvertisementMapper;
import com.atguigu.atcrowdfunding.manager.service.AdvertService;
import com.atguigu.atcrowdfunding.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author xzt
 * @create 2021-03-03 20:00
 */
@Service
public class AdvertServiceImpl implements AdvertService {

    @Autowired
    private AdvertisementMapper advertisementMapper;

    @Override
    public int insertAdvert(Advertisement advertisement) {
        return advertisementMapper.insert(advertisement);
    }

    @Override
    public Page queryPage(HashMap<String, Integer> paramMap) {

        Page page = new Page(paramMap.get("pageNo"),paramMap.get("pageSize"));

        Integer startIndex = page.startIndex();

        paramMap.put("startIndex",startIndex);

        List<Advertisement> datas = advertisementMapper.queryPage(paramMap);

        page.setDatas(datas);

        Integer totalSize = advertisementMapper.queryCount(paramMap);

        page.setTotalSize(totalSize);

        return page;
    }
}
